home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 1995 #5 & #6 / Amiga Plus CD - 1995 - No. 5 and 6.iso / pd / netz / envoyempire / source / muiempire.service / muiempireservice.c < prev    next >
C/C++ Source or Header  |  1995-07-10  |  4KB  |  158 lines

  1. /*************************************************************************
  2.  
  3. MUIEmpire Service written by Karl Bellve
  4.  
  5.    
  6. *************************************************************************/
  7.  
  8.  
  9. #include <exec/types.h>
  10. #include <exec/memory.h>
  11. #include <exec/ports.h>
  12.  
  13. #include <utility/tagitem.h>
  14. /*
  15. #include <workbench/startup.h>
  16. */
  17. #include <dos/dostags.h>
  18. #include <dos.h>
  19.  
  20. #include <envoy/nipc.h>
  21. #include <envoy/services.h>
  22.  
  23. #include <pragmas/dos_pragmas.h>
  24. #include <pragmas/exec_pragmas.h>
  25. #include <pragmas/nipc_pragmas.h>
  26. #include <pragmas/utility_pragmas.h>
  27. #include <clib/dos_protos.h>
  28. #include <clib/exec_protos.h>
  29. #include <clib/nipc_protos.h>
  30. #include <clib/alib_protos.h>
  31. #include <clib/utility_protos.h>
  32.  
  33. #include "string.h"
  34. #include "stdio.h"
  35.  
  36. int  __saveds __UserLibInit(void);
  37. void __saveds __UserLibCleanup(void);
  38.  
  39. struct Library *UtilityBase, *DOSBase;
  40.  
  41. struct MyMsg  /** Client/Server message to/from MUX and Protocol **/
  42. {
  43.   struct Message msg;
  44.   ULONG  Type;
  45.   ULONG  Length;            
  46.   UBYTE  *Data;
  47. };
  48.  
  49. #define ASM           __asm
  50. //StartServiceA   (struct TagItem *);
  51. //GetServiceAttrsA(struct TagItem *);
  52.  
  53. int x;
  54.  
  55. VOID __saveds ASM LIBRexxReserved() { return; }
  56.  
  57.  
  58. /**************************************************************************
  59. StartService() - Starts the service.
  60.  
  61.     Services Manager calls this function to attempt to start the service.
  62.  
  63.     INPUTS: TagList passed in by Services Manager
  64.     OUTPUT: Error Code - Non Zero Means Error
  65. **************************************************************************/
  66. ULONG __saveds ASM LIBStartServiceA(register __a0 struct TagItem *st_list)
  67. {
  68.     struct TagItem cptags[3],*tag;
  69.     char   name[30];
  70.     ULONG  MUIEmpireError = 0;
  71.     struct MyMsg *mmsg;
  72.     struct MsgPort *parentport;
  73.     BOOL foo = TRUE;
  74.  
  75.     x++;
  76.     sprintf(&name[0],"empireserver.%d\0",x);
  77.     if (parentport = CreateMsgPort())
  78.       {
  79.       parentport->mp_Node.ln_Name = "MUIEmpire_service.port";
  80.       parentport->mp_Node.ln_Pri = 0;
  81.       AddPort(parentport);
  82.     }
  83.     cptags[0].ti_Tag  = NP_Name;
  84.     cptags[0].ti_Data = (ULONG) name;
  85.     cptags[1].ti_Tag  = SYS_Asynch;
  86.     cptags[1].ti_Data = TRUE;
  87.     cptags[2].ti_Tag  = TAG_DONE;
  88.     cptags[2].ti_Data = NULL;
  89.             
  90.  
  91.     MUIEmpireError = SystemTagList("Empire:EnvoyEmpireServer",(struct TagItem *)cptags);
  92.     
  93.     while (foo) {
  94.       while (mmsg = (struct MyMsg *)GetMsg(parentport)) {
  95.         if (mmsg->Type == 1) memcpy(mmsg->Data,name,30);
  96.         if (mmsg->Type == 2) foo = FALSE;
  97.         ReplyMsg((struct Message *)mmsg);
  98.       }
  99.       if (foo) WaitPort (parentport);
  100.     }
  101.     
  102.     if(tag=FindTagItem(SSVC_EntityName,st_list))
  103.       {
  104.       strcpy((char *)tag->ti_Data,name);
  105.       }
  106.     else MUIEmpireError = 1;
  107.     
  108.     if (parentport)   {
  109.        if (parentport->mp_Node.ln_Name)   RemPort(parentport);
  110.        DeletePort(parentport);
  111.     }
  112.  
  113.     return(MUIEmpireError);
  114. }
  115.  
  116.  
  117.  
  118. /*************************************************************************
  119. GetServiceAttrsA() - Get service attributes
  120.  
  121.     Required to return the name of the service in tag SVCAttrs_Name
  122.  
  123.     INPUTS: TagList from services manager to process/update
  124. *************************************************************************/
  125. VOID __saveds ASM LIBGetServiceAttrsA(register __a0 struct TagItem *tagList)
  126. {
  127.     struct TagItem *ti;
  128.  
  129.     if(ti=FindTagItem( SVCAttrs_Name, tagList))
  130.     {
  131.         strcpy((STRPTR)ti->ti_Data,"MUIEmpire_Service");
  132.     }
  133. }
  134.  
  135.  
  136. int __saveds __UserLibInit(void) {
  137.   
  138.   UtilityBase = OpenLibrary("utility.library",37);
  139.   DOSBase = OpenLibrary("dos.library",37);
  140.   
  141.   if (!DOSBase) return(1);
  142.   if (!UtilityBase){
  143.      CloseLibrary(DOSBase);
  144.      return (1);
  145.   }
  146.  
  147.   return(0);
  148. }
  149.  
  150. void __saveds __UserLibCleanup(void) {
  151.   
  152.   
  153.   CloseLibrary(DOSBase);
  154.   CloseLibrary(UtilityBase);
  155.    
  156.   return;
  157. }
  158.